package com.yiyang.pojo.vo;


import com.yiyang.utils.BizCode;
import io.swagger.v3.oas.annotations.media.Schema;
import lombok.AllArgsConstructor;
import lombok.Data;
import lombok.NoArgsConstructor;

import java.io.Serializable;

@Data
@NoArgsConstructor
@AllArgsConstructor
@Schema(name = "Result" , description = "统一结果集对象")
public class Result<T> implements Serializable {
    // 序列化版本号
    private static final  long serialVersionUID = 1L;
    @Schema(name = "code" , description = "统一状态码")
    // 状态码
    private Integer code;
    @Schema(name = "message" , description = "统一响应的状态信息")
    // 状态信息
    private String message;
    @Schema(name = "data" , description = "统一相应的数据")
    private T data;

    public static <Q> Result<Q> success(){
        return new Result<>(2000,"成功",null);
    }

    public static <Q> Result<Q> success(BizCode bizCode){
        return new Result<>(bizCode.getCode(),bizCode.getMsg(),null);
    }

    // 传递对应的数据
    public static <Q> Result<Q> success(BizCode bizCode,Q data){
        return new Result<>(bizCode.getCode(),bizCode.getMsg(),data);
    }
    // 传递数据和状态码
    public static <Q> Result<Q> success(Integer code,Q data){
        return new Result<>(code,"成功",data);
    }
    // 传递数据和状态信息
    public static <Q> Result<Q> success(String message,Q data){
        return new Result<>(2000,message,data);
    }
    // 传递所有成员变量参数
    public static <Q> Result<Q> success(Integer code,String message,Q data){
        return new Result<>(code,message,data);
    }

    /**
     * 响应失败
     * */

    public static <Q> Result<Q> fail(){
        return new Result<>(5000,"失败",null);
    }
    public static <Q> Result<Q> fail(BizCode bizCode){
        return new Result<>(bizCode.getCode(),bizCode.getMsg(),null);
    }
    // 传递对应的数据
    public static <Q> Result<Q> fail(Q data){
        return new Result<>(5000,"失败",data);
    }
    // 传递数据和状态码
    public static <Q> Result<Q> fail(Integer code,Q data){
        return new Result<>(code,"失败",data);
    }
    // 传递数据和状态信息
    public static <Q> Result<Q> fail(String message,Q data){
        return new Result<>(5000,message,data);
    }
    // 传递所有成员变量参数
    public static <Q> Result<Q> fail(Integer code,String message,Q data){
        return new Result<>(code,message,data);
    }
    public static <Q> Result<Q> fail(BizCode bizCode,Q data){
        return new Result<>(bizCode.getCode(), bizCode.getMsg(), data);
    }
}
